package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;
import java.util.SplittableRandom;

public class UpdateUserDemo {
    public static void main(String[] args) throws Exception{
        Connection conn = DBUtil.getConnection();
        System.out.println("与数据库连接成功！");
        UserInfo user = InputUtil.getInputObject(new UserInfo(),"修改用户信息");
        Statement stat = conn.createStatement();
        String sql = "UPDATE userinfo " +
                     "SET password='"+ user.getPassword()+
                     "',nickname='"+ user.getNickname()+
                     "',age='" + user.getAge()+" '" +
                     "WHERE username='"+ user.getUsername()+"'";
        int num = stat.executeUpdate(sql);
        System.out.println(num>0?"修改成功":"用户不存在");
    }
}
